#ifndef DATA_H
#define DATA_H

#include <QWidget>
#include <QStandardItemModel>
#include "blldataflow.h"
#include "sqlhelper.h"
#include "datetimepicker.h"
#include "iexportable.h"

namespace Ui {
class Data;
}

class IDataExport;
class Data : public QWidget, public IExportable
{
    Q_OBJECT

public:
    explicit Data(QWidget *parent = nullptr);
    ~Data();

    void save(const QString &path);

private slots:
    void on_btnQuery_clicked();
    void on_btnPrint_clicked();
    void on_btnExport_clicked();
    void on_btnDateTimeEditStart_clicked();
    void on_btnDateTimeEditEnd_clicked();

    void setWidgetVisibleSlot(int permission);
    void showAllParameters();
    void showAllMaterialType();
    void showAllResultType();

    void retranslateUiSlot();
    void changeDateTime(QDateTime dateTime, QString whatsThis);
    void setCurrentTimeSlot(int type);
    void viewReportSlot();

    void pdfSaveDone(const QString &info, const QString &path);

protected:
    void showEvent(QShowEvent *);

private:
    void initWidget();
    void showExperimentInfo(QList<ExperimentInfo> expList);
    void initTableHeader();
    QString generateTable(QStringList header, QList<ExperimentInfo> info);
    void setReportHtml(int type, const QString html);
    void resizeTableColumnWidth();
    void retranslateTable();
    bool hasViewAllDataPermission();
    void dataCalc(const ExperimentInfo &data, QString &vrmsStr, QString &offsetStr);
    QString translate(const QString &result);

private:
    Ui::Data *ui;
    BllDataFlow * bdf;
    SqlHelper * sqlHelper;
    QList<ExperimentInfo> expList;
    QStringList tableHeader;
    int rowNum;
    DateTimePicker * dateTimePicker;
    QString contentHtml;
    QString reportHtml;
    IDataExport *exportMgr;
};

#endif // DATA_H
